/*
 * 项目名称:    wms-server-jeecg
 * 创建人员:    DongPeng
 * 创建时间:    2023-07-25
 * copyright(c) 2022 无锡星智数服科技有限公司
 */
package org.jeecg.modules.quartz.job;

import cn.hutool.core.util.ObjectUtil;
import lombok.extern.slf4j.Slf4j;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;

import java.util.Set;

/**
 * redis序列计数器job
 *
 * @author DongPeng
 * @version 1.0.0
 * @date 2023-07-25
 * @description 类描述
 */
@Slf4j
public class SequenceJob implements Job {

    @Autowired
    private RedisTemplate redisTemplate;
    /**
     * 每天早上0点0分0秒重置redis序列计数器
     */
    @Override
    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
        String key = "x_sequence_business";
        Set<String> sets = redisTemplate.keys(key);
        log.info("重置序列计数器的key为：" + sets);
        if (!ObjectUtil.isEmpty(sets)) {
            redisTemplate.delete(sets);
            log.info("重置序列计数器完成！");
        }else {
            log.info("序列计数器无需重置！");
        }
    }
}
